package com.hlf.modules.h5.controller;

import com.hlf.common.annotation.SysLog;
import com.hlf.common.constants.Constants;
import com.hlf.common.constants.FileConstants;
import com.hlf.common.utils.ReturnResult;
import com.hlf.modules.h5.annotation.LoginUser;
import com.hlf.modules.merchant.store.entity.Store;
import com.hlf.modules.merchant.store.service.StoreService;
import com.hlf.modules.merchant.table.entity.Table;
import com.hlf.modules.merchant.table.service.TableService;
import com.hlf.modules.sys.entity.File;
import com.hlf.modules.sys.service.FileService;
import com.hlf.modules.wechat.model.Customer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/11/5.
 */

@Api("H5门店接口")
@RestController
@RequestMapping("/h5/store/")
public class H5StoreController {

    @Autowired
    private TableService tableService;
    @Autowired
    private StoreService storeService;
    @Autowired
    private FileService fileService;

    /**
     * 用餐门店-餐桌/门店信息
     */
    @SysLog("h5用餐门店-餐桌/门店信息")
    @ApiOperation(value = "用餐门店-餐桌/门店信息", notes = "用餐门店-餐桌/门店信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "token", value = "token", required = true),
    })
    @GetMapping(value = "/info")
    public ReturnResult info(@LoginUser Customer customer){
        Long spendTableId = customer.getSpendTableId();
        Long spendStoreId = customer.getSpendStoreId();
        Table table = tableService.queryObjectForId(spendTableId);
        Store store = storeService.queryObject(spendStoreId);
        Long id = store.getId();
        List<File> select = fileService.select(FileConstants.LOGO_IMG, id);
        Map<String, Object> map = new HashMap<>();
        map.put("storeName",store.getName());
        map.put("tableNum",table.getTableNum());
        if (select.size()>0){
            File file = select.get(0);
            map.put("logo",file);
        }
        return ReturnResult.ok().put(Constants.DEFAULT_RESULT_NAME,map);
    }

}
